package com.ruoyi.web.controller.inventory;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ProductInventory;
import com.ruoyi.system.service.IProductInventoryService;
import com.ruoyi.system.util.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品库存 Controller
 *
 * @author ruoyi
 * @date 2025-06-04
 */
@Api(tags = "门店商品库存管理")
@RestController
@RequestMapping("/product-inventory")
public class ProductInventoryController extends BaseController {

    @Autowired
    private IProductInventoryService productInventoryService;


    /**
     * 分页查询商品库存
     */
    @ApiOperation("分页查询商品库存")
    @PostMapping("/page")
    public BaseResponse<IPage<ProductInventory>> page(@RequestBody ProductInventory productInventory) {
        IPage<ProductInventory> result = productInventoryService.page(productInventory);
        return BaseResponse.success(result);
    }

    /**
     * 导出
     */
    @ApiOperation("导出")
    @PostMapping("/export")
    public void export(@RequestBody ProductInventory productInventory, HttpServletResponse response) {
        ExcelUtil<ProductInventory> util = new ExcelUtil<ProductInventory>(ProductInventory.class);
        List<ProductInventory> list = productInventoryService.export(productInventory);
        util.exportExcel(response, list, "库存总览列表");
    }

    /**
     * 根据ID查询详情
     */
    @ApiOperation("根据ID查询商品库存详情")
    @GetMapping("/detail/{id}")
    public BaseResponse<ProductInventory> detail(@PathVariable Integer id) {
        ProductInventory result = productInventoryService.getById(id);
        return BaseResponse.success(result);
    }
}
